% Function calculates the reflectance.
% Inputs:
% ------
%   photon_xyz => the current position of the photon in cartesian
%                 coordinates.
%   photon_dir => the cosine directions of the photon's path.
%   n1, n2     => reflective index's.
%
% Outputs:
% -------
%   alpha_t    => the transmitance angle.
%   t          => the reflectance of the photon.
function [t, alpha_t] = refl(photon_xyz, photon_dir, n1, n2)

R_p=photon_xyz(1,3)/photon_dir(1,3);
photon_xyz(1,1)=photon_xyz(1,1)+photon_dir(1,1)*R_p;
photon_xyz(1,2)=photon_xyz(1,2)+photon_dir(1,2)*R_p;
photon_xyz(1,3)=0;
alpha_i=acos(photon_dir(1,3));
alpha_t=asin(n2*sin(alpha_i)/n1);
t=1/2*((sin(alpha_i-alpha_t))^2/(sin(alpha_i+alpha_t))^2+(tan(alpha_i-alpha_t))^2/(tan(alpha_i+alpha_t))^2);
